<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>实现抽奖功能</title>
		<style type="text/css">
			#nav{
				width: 400px;
				margin: 0 auto;
				background-color: saddlebrown;
			}
			.option,#stare{
				border: 2px sandybrown solid;
				width: 100px;
				height: 50px;
				text-align: center;
				padding-top: 20px;
				float: left;
				
			}
			#stare{
				background-color: salmon;
			}
			.bg{
				border: 2px sandybrown solid;
				width: 100px;
				height: 50px;
				text-align: center;
				padding-top: 20px;
				float: left;
				background-color: red;
			}
			h2{
				font-size: 30px;
				color: blueviolet;
				padding-left: 20px;
			}
		</style>
	</head>
	<body>
		<div id="nav">
			<div class="option" id="jp1">
				谢谢惠顾
			</div>
			<div class="option" id="jp2">
				大奔一辆
			</div>
			<div class="option" id="jp3">
				谢谢惠顾
			</div>
			<div class="option" id="jp4">
				谢谢惠顾
			</div>
			<div id="stare">
				开始抽奖
			</div>
			<div class="option" id="jp5">
				100万
			</div>
			<div class="option" id="jp6">
				女朋友一个
			</div>
			<div class="option" id="jp7">
				谢谢惠顾
			</div>
			<div class="option" id="jp8">
				1000万
			</div>
			
		</div>
		<h2 id="h2"></h2>
		<script type="text/javascript">
			var option =  document.getElementsByClassName('option');
			var stare = document.getElementById('stare');
			var h2 = document.getElementById('h2');
			
			stare.onclick = function(){
				let num = 0;
				var timer = setInterval(function(){
					num++;
					var x = Math.floor(Math.random()*8);//生成随机数
					for(var i = 0 ; i< option.length ; i++){
						option[i].style.backgroundColor = '#FFFFFF';
						
					}
					option[x].style.backgroundColor='red';
					if(num == 6){
						clearInterval(timer);
						h2.innerHTML = option[x].innerHTML ;
						
					}
				},1000);
				
				
			}
		</script>
	</body>
</html>
